package com.zzx.day57Demo.DAO.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.context.annotation.Scope;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

import com.zzx.day57Demo.DAO.CraftDAO;
import com.zzx.day57Demo.model.Craft;


@Repository("craftDAO")
@Scope("prototype")
@SuppressWarnings("deprecation")
public class CraftDAOImpl extends HibernateDaoSupport implements CraftDAO {

	@Override
	public List<Craft> findAll() {
		return getHibernateTemplate().execute(new HibernateCallback<List<Craft>>() {

			@SuppressWarnings("unchecked")
			@Override
			public List<Craft> doInHibernate(Session session) throws HibernateException, SQLException {
				// TODO Auto-generated method stub
				return session.createCriteria(Craft.class).list();
			}
		});
	}

	@Override
	public void saveOrUpdate(Craft cra) {
		getHibernateTemplate().saveOrUpdate(cra);
		
	}

	@Override
	public Craft findById(Integer craId) {
		
		return getHibernateTemplate().get(Craft.class, craId);
	}

	@Override
	public void delete(Craft cra) {
		getHibernateTemplate().delete(cra);
		
	}

}
